﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Web.Configuration;

public partial class MasterPage : System.Web.UI.MasterPage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        AppInit();
    }

    protected void AppInit()
    {
        if (Application["gfcSiteID"] == null)
        {
            Configuration config =
                WebConfigurationManager.OpenWebConfiguration("~/");
            AppSettingsSection appSettings =
                config.GetSection("appSettings") as AppSettingsSection;
            Application["LocalSqlServer"] = 
                config.ConnectionStrings.ConnectionStrings["LocalSqlServer"].ConnectionString;

            if (appSettings.Settings["gfcSiteID"] != null)
            {
                Application["gfcSiteID"] =
                    (string)appSettings.Settings["gfcSiteID"].Value;
                Application["gfcSiteAuthId"] = 
                    "fcauth" + Application["gfcSiteID"];
                Application["gfcApiUrl"] =
                    (string)appSettings.Settings["gfcApiUrl"].Value;
                Application["gfcOAuthKey"] =
                    (string)appSettings.Settings["gfcOAuthKey"].Value;
                Application["gfcOAuthSecret"] =
                    (string)appSettings.Settings["gfcOAuthSecret"].Value;
            }
            else
            {
                Application["gfcSiteID"] = "";
                Application["gfcSiteAuthId"] = "";
                Application["gfcApiUrl"] = "";
                Application["gfcOAuthKey"] = "";
                Application["gfcOAuthSecret"] = "";
            }
        }
    }
}
